package com.faradel.pharmapp.dao;

import java.util.List;
import java.util.Map;

import org.faradel.pharmapp.entities.PharmaUser;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository("pharmaUserDaoImpl")
public class PharmaUserDaoImpl extends GenericDAOImpl<PharmaUser, Integer> implements PharmaUserDAO
{

    @SuppressWarnings(
        { "unchecked" })
    @Override
    public List<PharmaUser> findByColumn(Map<String, String> map)
    {
        Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(PharmaUser.class);
        for (Map.Entry<String, String> mapEntry : map.entrySet())
        {
            if (mapEntry.getKey().equalsIgnoreCase("providerId") || mapEntry.getKey().equalsIgnoreCase("jobId"))
            {
                criteria.add(Restrictions.eq(mapEntry.getKey(), Integer.parseInt(mapEntry.getValue())));
            }
            else if (mapEntry.getKey().equalsIgnoreCase("userStatus"))
            {
                boolean status = (mapEntry.getValue().equalsIgnoreCase("true") ? true : false);
                criteria.add(Restrictions.eq(mapEntry.getKey(), status));
            }
            else
            {
                criteria.add(Restrictions.eq(mapEntry.getKey(), mapEntry.getValue()));
            }
        }

        return criteria.list();
    }

}
